home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / stack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  5.9 KB  |  171 lines

  1. #ifndef __STD_STACK__
  2. #define __STD_STACK__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * stack - Declaration for the Standard Library stack class
  8.  *
  9.  * $Id: stack,v 1.26 1996/09/03 23:14:41 smithey Exp $
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * Copyright (c) 1994
  14.  * Hewlett-Packard Company
  15.  *
  16.  * Permission to use, copy, modify, distribute and sell this software
  17.  * and its documentation for any purpose is hereby granted without fee,
  18.  * provided that the above copyright notice appear in all copies and
  19.  * that both that copyright notice and this permission notice appear
  20.  * in supporting documentation.  Hewlett-Packard Company makes no
  21.  * representations about the suitability of this software for any
  22.  * purpose.  It is provided "as is" without express or implied warranty.
  23.  *
  24.  *
  25.  ***************************************************************************
  26.  *
  27.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  28.  * ALL RIGHTS RESERVED *
  29.  * The software and information contained herein are proprietary to, and
  30.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  31.  * intends to preserve as trade secrets such software and information.
  32.  * This software is furnished pursuant to a written license agreement and
  33.  * may be used, copied, transmitted, and stored only in accordance with
  34.  * the terms of such license and with the inclusion of the above copyright
  35.  * notice.  This software and information or any other copies thereof may
  36.  * not be provided or otherwise made available to any other person.
  37.  *
  38.  * Notwithstanding any other lease or license that may pertain to, or
  39.  * accompany the delivery of, this computer software and information, the
  40.  * rights of the Government regarding its use, reproduction and disclosure
  41.  * are as set forth in Section 52.227-19 of the FARS Computer
  42.  * Software-Restricted Rights clause.
  43.  * 
  44.  * Use, duplication, or disclosure by the Government is subject to
  45.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  46.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  47.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  48.  * P.O. Box 2328, Corvallis, Oregon 97339.
  49.  *
  50.  * This computer software and information is distributed with "restricted
  51.  * rights."  Use, duplication or disclosure is subject to restrictions as
  52.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  53.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  54.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  55.  * then the "Alternate III" clause applies.
  56.  *
  57.  **************************************************************************/
  58.  
  59. #include <stdcomp.h>
  60.  
  61. #ifndef _RWSTD_HEADER_REQUIRES_HPP
  62. #include <algorithm>
  63. #include <deque>
  64. #else
  65. #include <algorithm.hpp>
  66. #include <deque.hpp>
  67. #endif
  68.  
  69. #ifndef _RWSTD_NO_NAMESPACE
  70. namespace std {
  71. #endif
  72.  
  73. #ifdef _RWSTD_NO_UNDEFINED_FRIEND
  74. template <class T, class Container> class stack;
  75. template <class T, class Container>
  76. inline bool operator==(const stack<T,Container>& x, 
  77.                 const stack<T,Container>& y);
  78. template <class T, class Container>
  79. inline bool operator<(const stack<T,Container>& x, 
  80.                const stack<T,Container>& y);
  81. #endif  
  82.  
  83. #ifndef _RWSTD_NO_COMPLEX_DEFAULT_TEMPLATES
  84. template <class T, class Container = deque<T> >
  85. #else
  86. template <class T, class Container>
  87. #endif
  88. class stack
  89. {
  90.     friend bool operator== (const stack<T,Container>& x,
  91.                             const stack<T,Container>& y);
  92.     friend bool operator< (const stack<T,Container>& x,
  93.                            const stack<T,Container>& y);
  94.   public:
  95.  
  96.     typedef _TYPENAME Container::value_type  value_type;
  97.     typedef _TYPENAME Container::size_type   size_type;
  98.     typedef _TYPENAME Container::allocator_type        allocator_type;
  99.  
  100.   protected:
  101.     
  102.     Container c;
  103.  
  104.   public:
  105.     _EXPLICIT stack(const allocator_type& alloc _RWSTD_DEFAULT_ARG(allocator_type())) : c(alloc)
  106.     { ; }
  107.  
  108. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS    
  109.     stack(void) : c(allocator_type())
  110.     { ; }
  111. #endif
  112.     allocator_type get_allocator()
  113.     { return c.get_allocator(); }
  114.  
  115.     bool              empty ()                    const { return c.empty(); }
  116.     size_type         size  ()                    const { return c.size();  }
  117.     value_type&       top   ()                          { return c.back();  }
  118.     const value_type& top   ()                    const { return c.back();  }
  119.     void              push  (const value_type& x)       { c.push_back(x);   }
  120.     void              pop   ()                          { c.pop_back();     }
  121. };
  122.  
  123. template <class T, class Container>
  124. inline bool operator== (const stack<T,Container>& x, 
  125.                         const stack<T,Container>& y)
  126. {
  127.     return x.c == y.c;
  128. }
  129.  
  130. template <class T, class Container>
  131. inline bool operator< (const stack<T,Container>& x, 
  132.                        const stack<T,Container>& y)
  133. {
  134.     return x.c < y.c;
  135. }
  136.  
  137. template <class T, class Container>
  138. inline bool operator!= (const stack<T,Container>& x, 
  139.                         const stack<T,Container>& y)
  140. {
  141.     return !(x == y);
  142. }
  143.  
  144. template <class T, class Container>
  145. inline bool operator> (const stack<T,Container>& x, 
  146.                        const stack<T,Container>& y)
  147. {
  148.     return y < x;
  149. }
  150.  
  151. template <class T, class Container>
  152. inline bool operator>= (const stack<T,Container>& x, 
  153.                         const stack<T,Container>& y)
  154. {
  155.     return !(x < y);
  156. }
  157.  
  158. template <class T, class Container>
  159. inline bool operator<= (const stack<T,Container>& x, 
  160.                         const stack<T,Container>& y)
  161. {
  162.     return !(y <  x);
  163. }
  164.  
  165. #ifndef _RWSTD_NO_NAMESPACE
  166. }
  167. #endif
  168.  
  169. #pragma option pop
  170. #endif /*__STD_STACK__*/
  171.